﻿using Mapster;
using MapsterMapper;

namespace MXERP.Client.Extensions
{
    public static class MapsterServiceCollectionExtension
    {
        /// <summary>
        /// 注册Mapster
        /// </summary>
        /// <param name="services"></param>
        /// <param name="options"></param>
        public static void RegisterMapster(this IServiceCollection services, Action<TypeAdapterConfig>? options = null)
        {
            var config = new TypeAdapterConfig();
            //config.Default.PreserveReference(true);
            //var assembly = Assembly.GetAssembly(typeof(AppRegister));
            //if (assembly != null)
            //    config.Scan(assembly);
            options?.Invoke(config);
            services.AddSingleton(config);
            services.AddScoped<IMapper, ServiceMapper>();
        }
    }
}
